package com.blue.waffle.iwc.domains;

public enum Difficulties {
	EASY(1,true,true,5,false,new int[]{200,100,50},new int[]{0,30,45}),
	NORAML(2,false,true,3,true,new int[]{300,200,100},new int[]{0,20,30}),
	HARD(3,false,false,3,true,new int[]{300,200,100},new int[]{0,15,20});
	//HARD(3,false,false,3,true,new int[]{300,200,100},new int[]{0,2,3});
	private int id;
	private boolean validate;
	private boolean showDefinition;
	private int attempts;
	private boolean showTimer;
	private int[] scoresPerSecond;
	private int[] scoreSeconds;
	
	private Difficulties(int id,boolean validate,boolean showDef,int attemps,boolean timer,int[] scoresPerSecond, int[] scoreSeconds){
		this.id=id;
		this.validate=validate;
		this.attempts=attemps;
		this.showDefinition=showDef;
		this.showTimer=timer;
		this.scoreSeconds=scoreSeconds;
		this.scoresPerSecond=scoresPerSecond;
	}
	
	public float getAllowedPlayTime(){
		if (showTimer) {
			return scoreSeconds[scoreSeconds.length-1];
		}else {
			return -1;
		}
	}
	
	public static Difficulties getDifficulty(int id){
		for (Difficulties difficulty : values()) {
			if (difficulty.id==id) {
				return difficulty;
			}
		}
		return null;
	}
	
	public long calculateScore(float playedTimeInSeconds,int completedLetters){
		int length=scoreSeconds.length;
		
		float score=0;
		for (int i = 0; i < length; i++) {
			int secondRangeMin=scoreSeconds[i];
			if (i+1==length+1) {
				score=scoresPerSecond[i]*completedLetters+(secondRangeMin-playedTimeInSeconds)*completedLetters;
				break;
			}else {
				int secondRangeMax=scoreSeconds[i+1];
				if (playedTimeInSeconds>secondRangeMin&& playedTimeInSeconds<=secondRangeMax) {
					score=scoresPerSecond[i]*completedLetters+(secondRangeMax-playedTimeInSeconds)*completedLetters;
					break;
				}
			}
		}
		return (long) score;
	}
	
	public int getTimeLimit(){
		return scoreSeconds[scoreSeconds.length-1];
	}
	
	public int getId() {
		return id;
	}

	public boolean isShowDefinition() {
		return showDefinition;
	}
	
	public boolean isShowTimer() {
		return showTimer;
	}
	
	public boolean isValidate() {
		return validate;
	}
	
	public int getAttempts() {
		return attempts;
	}
	
	public int[] getScoreSeconds() {
		return scoreSeconds;
	}
	
	public int[] getScoresPerSecond() {
		return scoresPerSecond;
	}
}
